package com.project.controller;

import com.project.Util.MFUtil;
import com.project.bean.CUserBean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author lyl
 * description:
 */
@RestController
@RequestMapping("cuser")
public class CUserController {
    @RequestMapping("add")
    public String add(CUserBean cUserBean, @RequestParam("face") MultipartFile mf) throws IOException {
        String path = MFUtil.MFTrance(mf, "static/html/userImg");
        cUserBean.setImgPath(path.split("[.]")[0]);
        System.out.println(cUserBean);
        return "ok";
    }

    @RequestMapping("land")
    public String land(String userName, String pwd, HttpServletRequest request) {
        if ("java".equalsIgnoreCase(userName) && "123".equalsIgnoreCase(pwd)) {
            request.getSession().setAttribute("loginUser", "java");
            System.out.println(userName);
            return "ok";
        }
        return "no";
    }

    @RequestMapping("test")
    public String test(HttpServletRequest request) {
        String name = request.getParameter("name");
        return name;

    }

}
